﻿
#!/usr/bin/python
# -*- coding=utf-8 -*-
import wx
import qurany

class QuranSearch(wx.Frame):



    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(450, 400))
        panel = wx.Panel(self, -1)
        #-------- Declare Input Fields ------
        global tc
        global tc2
        global sura
        global ayaa
        _icon = wx.EmptyIcon()
        _icon.CopyFromBitmap(wx.Bitmap(u"C:\\Users\\Ahmed Salem\\Pictures\\styleislam_icons\\styleislam\\LINUX\\kuran\\kuran_20_32x32x32.png",
                                      wx.BITMAP_TYPE_ANY))
        self.SetIcon(_icon)
        font1 = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Comic Sans MS')
        #font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
        #font.SetPointSize(9)

        vbox = wx.BoxSizer(wx.VERTICAL)
        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        st1 = wx.StaticText(panel, -1, 'Search by word')

        #st1.SetFont(font)
        hbox1.Add(st1, 0, wx.RIGHT, 8)
        #tc = wx.TextCtrl(panel, -1)
        tc = wx.SearchCtrl(panel, size=(200,-1), style=wx.TE_PROCESS_ENTER|wx.TE_RIGHT)


        hbox1.Add(tc, 1)
        vbox.Add(hbox1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP,15)
        # adding space
        vbox.Add((-1, 10))
        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        st2 = wx.StaticText(panel, -1, 'Matching In Quran')
        #st2.SetFont(font)
        #

        hbox2.Add(st2, 0)
        vbox.Add(hbox2, 0, wx.LEFT | wx.TOP, 10)

        vbox.Add((-1, 10))
        # adding outpur area
        hbox3 = wx.BoxSizer(wx.HORIZONTAL)
        tc2 = wx.TextCtrl(panel, -1,style=wx.TE_MULTILINE|wx.TE_RIGHT|wx.TE_RICH2)
        points = tc2.GetFont().GetPointSize()
        #f = wx.Font(points, wx.FONTFAMILY_SWISS,wx.TE_MULTILINE, wx.FONTWEIGHT_BOLD)
        #tc2.SetInsertionPoint(0)
        #( pointSize, family, style, weight, underline, face, encoding)
        f = wx.Font(13,  wx.SWISS, wx.ITALIC, wx.BOLD, True,u'MS Sans Serif')

        #tc2.SetStyle(0, 2, wx.TextAttr("blue",wx.NullColour, f))
        #tc2.SetDefaultStyle(wx.TextAttr(wx.BLUE))
        #f = wx.Font(points + 3, wx.ROMAN,wx.ITALIC, wx.BOLD, True)

        hbox3.Add(tc2, 1, wx.EXPAND)
        vbox.Add(hbox3, 1, wx.LEFT | wx.RIGHT | wx.EXPAND, 10)

        vbox.Add((-1, 25))

        hbox4 = wx.BoxSizer(wx.HORIZONTAL)
        sura =wx.TextCtrl(panel, -1)
        cb1 = wx.StaticText(panel, -1, 'Sura No.')
        #cb1.SetFont(font)
        hbox4.Add(cb1,0,wx.RIGHT, 10)
        hbox4.Add(sura,1,wx.RIGHT, 20)

        cb2 = wx.StaticText(panel, -1, 'Ayaa No.')
        ayaa= wx.TextCtrl(panel, -1)

        #cb2.SetFont(font)
        hbox4.Add(cb2, 0, wx.LEFT, 10)
        hbox4.Add(ayaa, 1, wx.LEFT, 20)
        vbox.Add(hbox4, 0, wx.LEFT, 10)

        vbox.Add((-1, 25))

        hbox5 = wx.BoxSizer(wx.HORIZONTAL)
        btn1 = wx.Button(panel, -1, 'Search', size=(70, 30))
        hbox5.Add(btn1, 0)

        close = wx.Button(panel, -1, 'Clear', size=(70, 30))
        hbox5.Add(close, 0, wx.LEFT | wx.BOTTOM , 5)
        vbox.Add(hbox5, 0, wx.ALIGN_RIGHT | wx.RIGHT, 10)

        panel.SetSizer(vbox)
        self.Centre()
        self.Show(True)

        #----------- Setting Event Handling ----------------
        self.Bind(wx.EVT_BUTTON, self.OnClose, id=close.GetId())
        self.Bind(wx.EVT_BUTTON, self.onSearch, id=btn1.GetId())



    def OnClose(self, event):

        dial = wx.MessageDialog(None, 'Are you sure to quit?', 'Question',
            wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
        ret = dial.ShowModal()
        if ret == wx.ID_YES:
            self.Destroy()
        else:
            event.Veto()

    def search_Number():

        print "Inside search by number"

    def onSearch(self, event):
        sur=sura.GetValue()
        aya= ayaa.GetValue()
        se_text = tc.GetValue()

        #--------Object from quran class---------------
        q = qurany.quran()
        m = q.read_quran()
        l=q.getlist(m)
        f = wx.Font(19,  wx.NORMAL,wx.NORMAL, wx.BOLD, False,u'Arabic Typesetting')

        f2 = wx.Font(21,  wx.NORMAL,wx.NORMAL, wx.NORMAL, False,u'Arabic Typesetting')
        if(len(sur)!=0 and len(aya)!=0):
            #print "Search by Number"
            usura=unicode(sur)
            uaya=unicode(aya)

            mlist = [[usura,uaya]]
            output = q.getayat(l,mlist)
            tc2.SetValue(' ')
            tc2.AppendText(u'بِسْمِ ٱللَّهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ ')
            tc2.AppendText("\t\t\t")


            tc2.SetStyle(0, 39, wx.TextAttr("blue",wx.NullColour, f))

            for i in range(0,len(output)):
                tc2.AppendText(unicode(output[i]))

            tc2.SetStyle(40, 40+len(output[0]), wx.TextAttr("black",wx.NullColour, f2))

        elif(len(se_text)!=0):
            l2 = q.searchOfWord(l,se_text)
            ah = q.getayat(l,l2)
            tc2.SetValue(' ')
            tc2.AppendText(u'بِسْمِ ٱللَّهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ ')
            tc2.AppendText("\t\t\t")
            tc2.SetStyle(0, 39, wx.TextAttr("blue",wx.NullColour, f))
            xx = len(ah)
            for i in range(0,len(ah)):
                tc2.AppendText(unicode(ah[i]))
                #tc2.AppendText("\n\n----------------------------------\n\n")
                tc2.SetStyle(40, 900, wx.TextAttr("black",wx.NullColour, f2))



app = wx.App()
QuranSearch(None, -1, 'Qurany Search')
app.MainLoop()
